package bb.lanxing.adapter.sport;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import bb.lanxing.R;

public class SportFinishFeelingAdapter
	extends RecyclerView.Adapter<SportFinishFeelingAdapter.ViewHolder>
{
	private int[] feelingIconList = {
		R.drawable.ic_sport_experience_relaxed, R.drawable.ic_sport_experience_easy,
		R.drawable.ic_sport_experience_suitable, R.drawable.ic_sport_experience_tired,
		R.drawable.ic_sport_experience_very_tired
	};
	private final String[] feelingLis;
	private OnItemClickListener listener;
	private Context mContext;

	public SportFinishFeelingAdapter(String[] feelingLis)
	{
		super();
		this.feelingLis = feelingLis;
	}

	public class ViewHolder extends RecyclerView.ViewHolder
	{
		ImageView icon;
		TextView name;

		public ViewHolder(@NonNull View itemView)
		{
			super(itemView);
			icon = itemView.findViewById(R.id.itemIcon);
			name = itemView.findViewById(R.id.itemText);
		}
	}

	public interface OnItemClickListener
	{
		void onItemClick(int position);
	}

	@NonNull
	@Override
	public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
	{
		mContext = parent.getContext();
		View view =
			LayoutInflater.from(mContext).inflate(R.layout.item_sport_feeling, parent, false);
		ViewHolder holder = new ViewHolder(view);
		return holder;
	}

	@Override
	public void onBindViewHolder(@NonNull ViewHolder holder, int position)
	{
		holder.icon.setImageResource(feelingIconList[position]);
		holder.name.setText(feelingLis[position]);
		holder.itemView.setOnClickListener(v -> {
			if (listener != null)
			{
				listener.onItemClick(position);
			}
		});
	}

	@Override
	public int getItemCount()
	{
		return feelingLis.length;
	}

	public void setOnItemClickListener(OnItemClickListener listener)
	{
		this.listener = listener;
	}
}